/****** MikroDebug.c *************************************************
 *	 Tyler Fultz
 *   
 *
 *	 
 **********************************************************************/

/****** Includes********* *********************************************/



void DisplayByte(char Row, char NUM);
void DisplayInt(char Row, int NUM);
void LED1on(void);
void LED1off(void);
void LED2on(void);
void LED2off(void);
void DebugTouch(void);



//Display Byte Function displayes 8 bits in binary form on a given row, right justified
void DisplayByte(char Row, char NUM)
{

   /* DisplayByte Function setup */
   char bytechar[] = "RC00000000";

   bytechar[0] = Row;
   bytechar[1] = '\023';
   int i;

   for (i = 2; i < 10; i++)
   {
      bytechar[i] = (NUM & 0x80 >> (i - 2)) ? '1' : '0';
   }

   Display(BKGD, bytechar);

}

//Display int displays 16 bits in binary form on a given row, right justified
void DisplayInt(char Row, int NUM)
{

   /* DisplayInt Function setup */
   char intchar[] = "RC0000000000000000";

   intchar[0] = Row;
   intchar[1] = '\013';
   int i;

   for (i = 2; i < 18; i++)
   {
      intchar[i] = (NUM & 0x8000 >> (i - 2)) ? '1' : '0';
   }

   Display(BKGD, intchar);

}

//turns simulated LED2 ON
void LED2on(void)
{

   DrawRectangle(305, 0, 316, 3, WHITE);

}

//turns simulated LED2 OFF
void LED2off(void)
{

   DrawRectangle(305, 0, 316, 3, BKGD);

}

//turns simulated LED1 ON
void LED1on(void)
{

   DrawRectangle(281, 0, 292, 3, WHITE);

}

//turns simulated LED1 OFF
void LED1off(void)
{

   DrawRectangle(281, 0, 292, 3, BKGD);

}

/****** DebugTouch ****************************************************
 *
 * 
 * When called, checks for coordiantes and displays the touched point
 * Requires MikroTouch.c
 *
 **********************************************************************/
void DebugTouch(){

    static int oldx;
    static int oldy;

    if ((tsx >= 0) && (tsy >= 0)){

        DrawRectangle(oldx-2,oldy-2,oldx+1,oldy+2, BKGD);
        oldx = tsx;
        oldy = tsy;
        /*Mark the spot with a box*/
        DrawRectangle(tsx-2,tsy-2,tsx+1,tsy+2, RED);
        
    }
    
}
